﻿using System;
using System.Configuration;
using System.Net.Configuration;
using System.Net.Mail;

namespace VioletDevelopmentLaboratory.Net.Web.Configuration
{
	public sealed class SmtpSectionManager : ConfigurationManagerBase
	{
		private SmtpSection section;

		public SmtpSectionManager()
		{
			this.section = (SmtpSection)base.GetConfigurationSection("system.net/mailSettings/smtp");
		}

		public void Modify(SmtpDeliveryMethod deliveryMethod, String from)
		{
			this.section.DeliveryMethod = deliveryMethod;
			this.section.From = from;

			this.Save();
		}

		public SmtpSection GetSmtpSection()
		{
			return this.section;
		}

		public void ModifyNetword(String host, Int32 port, Boolean defaultCredentials, String userName, String password)
		{
			this.section.Network.Host = host;
			this.section.Network.Port = port;
			this.section.Network.DefaultCredentials = defaultCredentials;
			this.section.Network.UserName = userName;
			this.section.Network.Password = password;

			this.Save();
		}

		public SmtpNetworkElement GetNetworkElement()
		{
			return this.section.Network;
		}

		public void ModifySpecifiedPickupDirectory(String pickupDirectoryLocation)
		{
			this.section.SpecifiedPickupDirectory.PickupDirectoryLocation = pickupDirectoryLocation;

			this.Save();
		}

		public SmtpSpecifiedPickupDirectoryElement GetSpecifiedPickupDirectoryElement()
		{
			return this.section.SpecifiedPickupDirectory;
		}
	}
}